package com.gitee.feizns.dynamic;

import java.util.Map;

/**
 * 一组键可值的实现
 * @author feizns
 * @since 2023/3/7
 */
public class Pair<K, V> implements Map.Entry<K, V> {

    private final K k;
    private V v;

    private Pair(K k, V v) {
        this.k = k;
        this.v = v;
    }

    @Override
    public K getKey() {
        return k;
    }

    @Override
    public V getValue() {
        return v;
    }

    @Override
    public V setValue(V value) {
        V oldValue = v;
        v = value;
        return oldValue;
    }

    /**
     * Pair
     * @param k k
     * @param v v
     * @return {@link Pair}<{@link K}, {@link V}>
     */
    public static <K, V> Pair<K, V> of(K k, V v) {
        return new Pair<>(k, v);
    }

}
